function [simdata] = fcn_get_simdata_hover(Z, acc1g, hovering_time, ss_time, dt)
%fcn_get_simdata_hover      This function generates simulated data for hovering.
%   [simdata] = fcn_get_simdata_hover(Z, acc1g, it_time, ss_time, dt)
%   This function calculates simulated data for a hovering flight. The
%   copter nose points west.

%   IN      Z           Height of the flyer
%   IN      acc1g       Gravity
%   IN      it_time     Time for hovering
%   IN      ss_time     Steady state time (time for the fusion algorithm to adjust to the actual attitude)
%   IN      dt          Sample period
%   OUT     simdata     Simulated data 

% Number of measured points for input time and ss_time
k = round(hovering_time/dt + ss_time/dt);

% Initial attitude (pointing west)
roll = 0;
pitch = 0;
yaw = -pi/2;
q_initial = quatmultiply([1 0 0 0], euler2quat2(roll, pitch, yaw, 'zyx', 'r'));
q_initial = q_initial / norm(q_initial);

% Sample times
for j=1:k,j;
    simdata.time(j,1) = j*dt;
end

% Position
simdata.X(1:k,1) = 0;
simdata.Y(1:k,1) = 0;
simdata.Z(1:k,1) = Z;
simdata.pos = [simdata.X simdata.Y simdata.Z];

% Velocity
simdata.vel(1:k, 1:3) = 0;

% Euler angles
simdata.phi(1:k,1) = roll;
simdata.theta(1:k,1) = pitch;
simdata.psi(1:k,1) = yaw;

% Gyro data
simdata.gyrob(1:k, 1:3) = 0;

% Direction vectors in inertial-frame
acci = [0 0 acc1g];
magi = [1 0 0];

simdata.acci = repmat(acci, k, 1);
simdata.magi = repmat(magi, k, 1);

% Transfer direction vectors from inertial to body-frame
for j=1:k,j;
    accb(j,:) = quatmultiply(quatconj(q_initial), quatmultiply([0 acci], q_initial));  
end

for j=1:k,j;
    magb(j,:) = quatmultiply(quatconj(q_initial), quatmultiply([0 magi], q_initial));  
end
accb = accb(:, 2:4);
magb = magb(:, 2:4);

% Direction vectors in body-frame
simdata.accb = accb;
simdata.magb = magb;

% Quaternion attitude
simdata.q = repmat(q_initial, k, 1);

end

